package iooperator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

/**
 * @Filename: NetworkOperation
 * @Author: czh
 * @Data:2023/7/4 10:45
 * 网络操作(URL)
 */
public class NetworkOperation {
    public static void main(String[] args) {
        BufferedReader bufferedReader = null;
        try {
            URL url = new URL("http://www.baidu.com");
            // 获取字节流
            InputStream inputStream = url.openStream();
            // 获取字符流
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
            // 添加缓存流
            bufferedReader = new BufferedReader(inputStreamReader);

            String line;
            while ((line = bufferedReader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bufferedReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
